package com.hqyj.mana.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hqyj.mana.enums.ResultEnum;
import com.hqyj.mana.pojo.ContractManagement;
import com.hqyj.mana.pojo.vo.ResultVO;
import com.hqyj.mana.service.ContractService;
@RestController
@RequestMapping("contract")
public class ContractController {
	@Autowired
	ContractService service;
	
	@RequestMapping("get.do")
	@ResponseBody
	public ResultVO getSalaryList(String userName,String userId){
		List<ContractManagement> list = service.selectAllContract(userName,userId);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(list);
		if(list == null){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		
		return resultVO;
	}
	
	@RequestMapping("add.do")
	@ResponseBody
	public ResultVO add(@RequestBody ContractManagement user){
		System.out.println(user.getEndDate());
		boolean add = service.add(user);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(add);
		if(add!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	
	@RequestMapping("update.do")
	@ResponseBody
	public ResultVO ContractUpdate(@RequestBody ContractManagement user){
		System.out.println(user.getContent());
		boolean update = service.update(user);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(update);
		if(update!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	
	@RequestMapping("delete.do")
	@ResponseBody
	public ResultVO ContractDel(Integer contractId){
		boolean delete = service.del(contractId);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(delete);
		if(delete!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
}
